﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing.Printing;
using Spire.Xls;
namespace WinFormsApp1
{
    public partial class From1 : Form
    {
        public From1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
           CardInfo info =  ReadCard.readCardInfo();
            if (info != null)
            {
                this.label2.Text = "当前:" + info.Name;
                ReadCard.excelData(info);
                if (info.code == 1)
                {
                    MessageBox.Show("读卡成功，已生成采集表!", "提示", MessageBoxButtons.OK);
                    this.label1.Text = "信息:" + "success";
                }
                
            }
            else
                this.label1.Text = "信息:" + "2001";

        }

        private void button2_Click(object sender, EventArgs e)
        {
            string exportExcelPath = "export.xlsx";
            Spire.Xls.Workbook workbook = new Spire.Xls.Workbook();
            workbook.LoadFromFile(exportExcelPath);
            Worksheet sheet = workbook.Worksheets[0];

            PrintDialog dialog = new PrintDialog();
            dialog.AllowPrintToFile = true;
            dialog.AllowCurrentPage = true;
            dialog.AllowSomePages = true;
            dialog.AllowSelection = true;
            dialog.UseEXDialog = true;
            dialog.PrinterSettings.Duplex = Duplex.Simplex;
            dialog.PrinterSettings.FromPage = 0;
            dialog.PrinterSettings.ToPage = 8;
            dialog.PrinterSettings.PrintRange = PrintRange.SomePages;
            
            workbook.PrintDialog = dialog;
            PrintDocument pd = workbook.PrintDocument;
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                pd.PrinterSettings = dialog.PrinterSettings;

                pd.Print(); 
            }

        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("将通过本地程序打开表格，请确认已安装Office或WPS", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                System.Diagnostics.Process p = new System.Diagnostics.Process();
                p.StartInfo.UseShellExecute = true;
                p.StartInfo.FileName = "BaseForm.xlsx";//
                p.Start();
            }
            
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("将通过本地程序打开表格，请确认已安装Office或WPS", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                System.Diagnostics.Process p = new System.Diagnostics.Process();
                p.StartInfo.UseShellExecute = true;
                p.StartInfo.FileName = "export.xlsx";//
                p.Start();
            }
        }
    }
}
